<!-- 编辑弹窗 -->
<template>
  <a-modal
    :width="460"
    :visible="visible"
    :confirm-loading="loading"
    :title="isUpdate?'修改通用区域':'添加通用区域'"
    :body-style="{paddingBottom: '8px'}"
    @update:visible="updateVisible"
    @ok="save">
    <a-form
      ref="form"
      :model="form"
      :rules="rules"
      :label-col="{md: {span: 6}, sm: {span: 24}}"
      :wrapper-col="{md: {span: 19}, sm: {span: 24}}">
                    
      <a-form-item label=":" name="parent_id">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入"
          v-model:value="form.parent_id"/>
      </a-form-item>
                                      
      <a-form-item label=":" name="lft">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入"
          v-model:value="form.lft"/>
      </a-form-item>
                                      
      <a-form-item label=":" name="rgt">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入"
          v-model:value="form.rgt"/>
      </a-form-item>
                                      
      <a-form-item label=":" name="depth">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入"
          v-model:value="form.depth"/>
      </a-form-item>
                                      
      <a-form-item label=":" name="scope">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入"
          v-model:value="form.scope"/>
      </a-form-item>
                                      
      <a-form-item label="唯一代码标识:" name="code">
        <a-input
          v-model:value="form.code"
          placeholder="请输入唯一代码标识"
          allow-clear/>
      </a-form-item>
                                      
      <a-form-item label="标识别名:" name="code_alias">
        <a-input
          v-model:value="form.code_alias"
          placeholder="请输入标识别名"
          allow-clear/>
      </a-form-item>
                                      
      <a-form-item label="标题名称:" name="name">
        <a-input
          v-model:value="form.name"
          placeholder="请输入标题名称"
          allow-clear/>
      </a-form-item>
                                      
      <a-form-item label="标题名称英文:" name="name_en">
        <a-input
          v-model:value="form.name_en"
          placeholder="请输入标题名称英文"
          allow-clear/>
      </a-form-item>
                                      
      <a-form-item label="创建时间:" name="created_at">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入创建时间"
          v-model:value="form.created_at"/>
      </a-form-item>
                                      
      <a-form-item label="创建者名称:" name="created_name">
        <a-input
          v-model:value="form.created_name"
          placeholder="请输入创建者名称"
          allow-clear/>
      </a-form-item>
                                      
      <a-form-item label="创建者id:" name="created_by">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入创建者id"
          v-model:value="form.created_by"/>
      </a-form-item>
                                      
      <a-form-item label="更新时间:" name="updated_at">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入更新时间"
          v-model:value="form.updated_at"/>
      </a-form-item>
                                      
      <a-form-item label="更新者名称:" name="updated_name">
        <a-input
          v-model:value="form.updated_name"
          placeholder="请输入更新者名称"
          allow-clear/>
      </a-form-item>
                                      
      <a-form-item label="更新者id:" name="updated_by">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入更新者id"
          v-model:value="form.updated_by"/>
      </a-form-item>
                                      
      <a-form-item label="禁用时间戳:" name="disabled_at">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入禁用时间戳"
          v-model:value="form.disabled_at"/>
      </a-form-item>
                                      
      <a-form-item label="禁用者id:" name="disabled_by">
        <a-input-number
          :min="0"
          class="ele-fluid"
          placeholder="请输入禁用者id"
          v-model:value="form.disabled_by"/>
      </a-form-item>
                                      
      <a-form-item label="禁用者名称:" name="disabled_name">
        <a-input
          v-model:value="form.disabled_name"
          placeholder="请输入禁用者名称"
          allow-clear/>
      </a-form-item>
                              
    </a-form>
  </a-modal>
</template>

<script>
                                                                                                                    
export default {
  name: 'commonregionsEdit',
  emits: [
    'done',
    'update:visible'
  ],
                                                                                                                        props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: Object.assign({}, this.data),
      // 表单验证规则
      rules: {
                      
        parent_id: [
          {required: true, message: '请输入', type: 'number', trigger: 'blur'}
        ],
                          
        lft: [
          {required: true, message: '请输入', type: 'number', trigger: 'blur'}
        ],
                          
        rgt: [
          {required: true, message: '请输入', type: 'number', trigger: 'blur'}
        ],
                          
        depth: [
          {required: true, message: '请输入', type: 'number', trigger: 'blur'}
        ],
                          
        scope: [
          {required: true, message: '请输入', type: 'number', trigger: 'blur'}
        ],
                          
        code: [
          {required: true, message: '请输入唯一代码标识', type: 'string', trigger: 'blur'}
        ],
                          
        code_alias: [
          {required: true, message: '请输入标识别名', type: 'string', trigger: 'blur'}
        ],
                          
        name: [
          {required: true, message: '请输入标题名称', type: 'string', trigger: 'blur'}
        ],
                          
        name_en: [
          {required: true, message: '请输入标题名称英文', type: 'string', trigger: 'blur'}
        ],
                          
        created_at: [
          {required: true, message: '请输入创建时间', type: 'number', trigger: 'blur'}
        ],
                          
        created_name: [
          {required: true, message: '请输入创建者名称', type: 'string', trigger: 'blur'}
        ],
                          
        created_by: [
          {required: true, message: '请输入创建者id', type: 'number', trigger: 'blur'}
        ],
                          
        updated_at: [
          {required: true, message: '请输入更新时间', type: 'number', trigger: 'blur'}
        ],
                          
        updated_name: [
          {required: true, message: '请输入更新者名称', type: 'string', trigger: 'blur'}
        ],
                          
        updated_by: [
          {required: true, message: '请输入更新者id', type: 'number', trigger: 'blur'}
        ],
                          
        disabled_at: [
          {required: true, message: '请输入禁用时间戳', type: 'number', trigger: 'blur'}
        ],
                          
        disabled_by: [
          {required: true, message: '请输入禁用者id', type: 'number', trigger: 'blur'}
        ],
                          
        disabled_name: [
          {required: true, message: '请输入禁用者名称', type: 'string', trigger: 'blur'}
        ],
                          
        description: [
          {required: true, message: '请输入说明备注', type: 'string', trigger: 'blur'}
        ],
                    },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
      if (this.$refs.form) {
        this.$refs.form.clearValidate();
      }
    }
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs.form.validate().then(() => {
        this.loading = true;
        this.$http.post('/commonregions/edit', this.form).then(res => {
          this.loading = false;
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            if (!this.isUpdate) {
              this.form = {};
            }
            this.updateVisible(false);
            this.$emit('done');
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          this.loading = false;
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
</style>
